// javamaps
// Copyright (c) 2010 Lup Gratian
package Rendering.Animations;
import Rendering.IInterpolation;

public final class ExpInterpolation implements IInterpolation {
    public enum Mode {
        EaseIn,
        EaseOut,
        EaseInOut
    }

    /*
     * Membrii.
     */
    private double exponent_;
    private Mode mode_;

    /*
     * Constructori.
     */
    public ExpInterpolation(double exponent, Mode mode) {
        exponent_ = exponent;
        mode_ = mode;
    }

    /*
     * Metode publice.
     */
    public double GetValue(double start, double end, double progress) {
        double scale;
        if(mode_ == Mode.EaseIn) scale = EaseIn(progress);
        else if(mode_ == Mode.EaseOut) scale = 1.0 - EaseIn(1.0 - progress);
        else {
            if(progress < 0.5) {
                scale = EaseIn(progress * 2.0) * 0.5;
            }
            else {
                scale =  ((1.0 - EaseIn((1.0 - progress) * 2.0)) * 0.5) + 0.5;

            }
        }

        return start + ((end - start) * scale);
    }

    /*
     * Metode private.
     */
    private double EaseIn(double progress) {
        return (Math.exp(exponent_ * progress) - 1.0) /
               (Math.exp(exponent_) - 1.0);
    }
}